#pragma once

#include  <cv.h> 
#include <highgui.h> 
#include <cxcore.h> 

class CCarDetect
{
public:
	CCarDetect(void);
	void SetRoi(CvRect roi);
	bool CarDetectFramePro(IplImage * pFrame);
	CvSeq*GetRectSeq();
	virtual ~CCarDetect(void);

protected:
	void Init(IplImage *pImage);
	void DetectCar(IplImage *pFrame,CvSeq *pDetectCarSeq);

	int   GetAdaptiveThreDet( int nAvg1, int nAvg2 );
	void GetMask(CvSeq *pDetectCarSeq,IplImage *pMask);
	void RemoveIntersectedRects( CvSeq* pObjRects );
	void UnitNearRects(CvSeq *pObjRects);
	IplImage* GetSubImage(IplImage *pImage,CvRect roi);

protected:
    bool      isFirstFrame;
	CvRect  roi;
	int        iFrameCount;

	CvMat   *pBGMat;
	CvMemStorage* pMemStorCar;
	CvSeq *pCarSeq;

	bool        isNewRoi;

	//temp 
	CvMat     *pFrameMat;
	CvMat     *pFgMat;

	IplImage *pFgFrame ;
	IplImage *pMask;
	IplImage *pGrayImage;
	IplImage *pResizeImage;
	IplImage *pSubImage;

	CvMemStorage* pStorageObjs;
};
